package com.ruoyi.gatewayadmin.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.gatewayadmin.mapper.GatewayRouterMapper;
import com.ruoyi.gatewayadmin.domain.GatewayRouter;
import com.ruoyi.gatewayadmin.service.IGatewayRouterService;

/**
 * 路由定义Service业务层处理
 *
 * @author Darwin
 * @date 2024-10-13
 */
@Service
@DataSource(value = DataSourceType.SLAVE)
public class GatewayRouterServiceImpl implements IGatewayRouterService {
    @Autowired
    private GatewayRouterMapper gatewayRouterMapper;

    /**
     * 查询路由定义
     *
     * @param uuid 路由定义主键
     * @return 路由定义
     */
    @Override
    public GatewayRouter selectGatewayRouterByUuid(String uuid) {
        return gatewayRouterMapper.selectGatewayRouterByUuid(uuid);
    }

    /**
     * 查询路由定义列表
     *
     * @param gatewayRouter 路由定义
     * @return 路由定义
     */
    @Override
    public List<GatewayRouter> selectGatewayRouterList(GatewayRouter gatewayRouter) {
        return gatewayRouterMapper.selectGatewayRouterList(gatewayRouter);
    }

    /**
     * 新增路由定义
     *
     * @param gatewayRouter 路由定义
     * @return 结果
     */
    @Override
    public int insertGatewayRouter(GatewayRouter gatewayRouter) {
        String uuid = String.valueOf(UUID.fastUUID());
        gatewayRouter.setUuid(uuid);
        gatewayRouter.setCreated(new Date());
        String username = SecurityUtils.getUsername();
        gatewayRouter.setCreatedBy(username);
        gatewayRouter.setUpdated(new Date());
        gatewayRouter.setUpdatedBy(username);
        return gatewayRouterMapper.insertGatewayRouter(gatewayRouter);
    }

    /**
     * 修改路由定义
     *
     * @param gatewayRouter 路由定义
     * @return 结果
     */
    @Override
    public int updateGatewayRouter(GatewayRouter gatewayRouter) {

        gatewayRouter.setUpdatedBy(SecurityUtils.getUsername());
        gatewayRouter.setUpdated(new Date());
        return gatewayRouterMapper.updateGatewayRouter(gatewayRouter);
    }

    /**
     * 批量删除路由定义
     *
     * @param uuids 需要删除的路由定义主键
     * @return 结果
     */
    @Override
    public int deleteGatewayRouterByUuids(String[] uuids) {
        return gatewayRouterMapper.deleteGatewayRouterByUuids(uuids);
    }

    /**
     * 删除路由定义信息
     *
     * @param uuid 路由定义主键
     * @return 结果
     */
    @Override
    public int deleteGatewayRouterByUuid(String uuid) {
        return gatewayRouterMapper.deleteGatewayRouterByUuid(uuid);
    }
}
